package com.yyysj.system.controller;

import com.yyysj.common.core.domain.Result;
import com.yyysj.system.domain.dto.CommentDTO;
import com.yyysj.system.domain.dto.PostDTO;
import com.yyysj.system.domain.vo.CommentVO;
import com.yyysj.system.domain.vo.PostVO;
import com.yyysj.system.service.ICommentService;
import com.yyysj.system.service.IPostService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Tag(name = "帖子和评论管理接口")
@RequiredArgsConstructor
public class ArticleController {

    private final IPostService postService;
    private final ICommentService commentService;

    @GetMapping("/post/list")
    public Result<PostVO> getPostList(
            @RequestParam(required = false) String title,
            @RequestParam(required = false) Long postId,
            @RequestParam(required = false) Long userId,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        return Result.ok(postService.getPostList(title, postId, userId, pageNum, pageSize));
    }

    @PutMapping("/post/status")
    public Result<?> updatePostStatus(@RequestBody PostDTO postDTO) {
        return Result.build(postService.updatePostStatus(postDTO.getPostId(), postDTO.getStatus()));
    }

    @DeleteMapping("/post/delete")
    public Result<?> deletePost(@RequestBody PostDTO postDTO) {
       return Result.build(postService.deletePost(postDTO.getPostId()));
    }

    // 获取评论列表
    @GetMapping("/comment/list")
    public Result<CommentVO> getCommentList(CommentDTO commentDTO) {
        return Result.ok(commentService.getCommentList(commentDTO));
    }

    // 更新评论状态
    @PutMapping("/comment/status")
    public Result<?> updateCommentStatus(@RequestBody CommentDTO commentDTO) {
        return Result.build(commentService.updateCommentStatus(commentDTO.getCommentId(), commentDTO.getStatus()));
    }

    // 删除评论
    @DeleteMapping("/comment/delete")
    public Result<?> deleteComment(@RequestBody CommentDTO commentDTO) {
        return Result.build(commentService.deleteComment(commentDTO.getCommentId()));
    }
}
